<?php
/**
 * @version     1.0.4
 * @package     com_hotels
 * @copyright   Copyright (C) 2014. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Russell English <russell.english@stormit.co.uk> - http://www.stormit.co.uk
 */
// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');

function seoParseString($string) {
	return trim(str_replace('--', '-', preg_replace('#[^a-z0-9\-]#', '-', strtolower($string))), '-');
}

$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->state->get('list.ordering');
$listDirn = $this->state->get('list.direction');
$canCreate = $user->authorise('core.create', 'com_hotels');
$canEdit = $user->authorise('core.edit', 'com_hotels');
$canCheckin = $user->authorise('core.manage', 'com_hotels');
$canChange = $user->authorise('core.edit.state', 'com_hotels');
$canDelete = $user->authorise('core.delete', 'com_hotels');

?>

<? if (count($this->items) != 0): ?>
<form action="<?php echo JRoute::_('index.php?option=com_hotels&view=available'); ?>" method="post" name="adminForm" id="adminForm">
			<div class="top">
					<?php echo $this->pagination->getListFooter(); ?></div>
  <div class="table">
    <div class="tbrow tbtitle">
      <div class="tbcol"> <?php echo JHtml::_('grid.sort',  'Hotel', 'a.hotelname', $listDirn, $listOrder); ?> </div>
      <div class="tbcol"> <?php echo JHtml::_('grid.sort',  'Resort', 'a.resortname', $listDirn, $listOrder); ?> </div>
      <div class="tbcol"> <?php echo JHtml::_('grid.sort',  'Dep', 'a.dep', $listDirn, $listOrder); ?> </div>
      <div class="tbcol"> <?php echo JHtml::_('grid.sort',  'Date', 'a.startdate', $listDirn, $listOrder); ?> </div>
      <div class="tbcol"> <?php echo JHtml::_('grid.sort',  'Price', 'a.sellingprice', $listDirn, $listOrder); ?>
        <div class="ico-twoadults"></div>
      </div>
      <div class="tbcol">
        <div class="tbnote"> Based on <br>
          2 Adults </div>
      </div>
    </div>
    <?php foreach ($this->items as $i => $item) : ?>
    <?php $canEdit = $user->authorise('core.edit', 'com_hotels'); ?>
    <div class="tbrow <?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1); ?>">
      <div class="tbcol">
        <?php $url = 'http://rocketski.com/ski-resorts/france/' . seoParseString($item->resortname) . '/' . seoParseString($item->hotelname); ?>
        <a href="<?php echo $url; ?>"> <?php echo $this->escape(ucwords(strtolower($item->hotelname))); ?> </a> </div>
      <div class="tbcol"> <?php echo ucwords(strtolower($item->resortname)); ?> </div>
      <div class="tbcol"> <?php echo $item->dep; ?> </div>
	  <?php $depdate = date("d/m/Y", strtotime(seoParseString($item->startdate))); ?>
      <div class="tbcol"> <?php echo $depdate; ?> </div>
      <div class="tbcol"> £<?php echo $item->sellingprice; ?> </div> 
      <?php $urlbook = 'http://bookings.rocketski.com/engine3/res_BookingLink.aspx?hotel='.seoParseString($item->hotelcode).'&reqdate='.$depdate.'&aprt='.seoParseString($item->dep); ?>
      <div class="tbcol"> <span class="cta"><a href="<?php echo $urlbook; ?>">more >></a></span> </div>
    </div>
    <?php endforeach; ?>
  </div>
  			<div class="bottom">
					<?php echo $this->pagination->getListFooter(); ?>
</div>
  <?php if ($canCreate): ?>
  <a href="<?php echo JRoute::_('index.php?option=com_hotels&task=availability.edit&id=0', false, 2); ?>" class="btn btn-success btn-small"><i class="icon-plus"></i> <?php echo JText::_('COM_HOTELS_ADD_ITEM'); ?></a>
  <?php endif; ?>
  <input type="hidden" name="task" value="" />
  <input type="hidden" name="boxchecked" value="0" />
  <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
  <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
  <?php echo JHtml::_('form.token'); ?>
</form>
<? else: ?>
<p>
  <strong style="color:red"><?php echo JText::_('COM_HOTELS_NO_RESULTS'); ?></strong>
</p>
<? endif; ?>
<? foreach ($this->similarItems as $type => $items): ?>

    <? if ($items): ?>

        <h1 class="greent" style="margin-top:20px"><?= $type == "other_dates"?JText::_('COM_HOTELS_TRY_DIFFERENT_DATE'):JText::_('COM_HOTELS_TRY_DIFFERENT_RESORT') ?></h1>
        <form action="<?php echo JRoute::_('index.php?option=com_hotels&view=available'); ?>" method="post" name="adminForm" id="adminForm">
                    <div class="top">
          <div class="table">
            <div class="tbrow tbtitle">
              <div class="tbcol"> Hotel </div>
              <div class="tbcol"> Resort </div>
              <div class="tbcol"> Dep </div>
              <div class="tbcol"> Date </div>
              <div class="tbcol"> Price 
                <div class="ico-twoadults"></div>
              </div>
              <div class="tbcol">
                <div class="tbnote"> Based on <br>
                  2 Adults </div>
              </div>
            </div>
            <?php foreach ($items as $i => $item) : ?>
            <?php $canEdit = false ?>
            <div class="tbrow <?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1); ?>">
              <div class="tbcol">
                <?php $url = 'http://rocketski.com/ski-resorts/france/' . seoParseString($item->resortname) . '/' . seoParseString($item->hotelname); ?>
                <a href="<?php echo $url; ?>"> <?php echo $this->escape(ucwords(strtolower($item->hotelname))); ?> </a> </div>
              <div class="tbcol"> <?php echo ucwords(strtolower($item->resortname)); ?> </div>
              <div class="tbcol"> <?php echo $item->dep; ?> </div>
              <?php $depdate = date("d/m/Y", strtotime(seoParseString($item->startdate))); ?>
              <div class="tbcol"> <?php echo $depdate; ?> </div>
              <div class="tbcol"> £<?php echo $item->sellingprice; ?> </div> 
              <?php $urlbook = 'http://bookings.rocketski.com/engine3/res_BookingLink.aspx?hotel='.seoParseString($item->hotelcode).'&reqdate='.$depdate.'&aprt='.seoParseString($item->dep); ?>
              <div class="tbcol"> <span class="cta"><a href="<?php echo $urlbook; ?>">more >></a></span> </div>
            </div>
            <?php endforeach; ?>
          </div>
        </form>
    <? endif; ?>
<? endforeach; ?>
